/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__frhash_make_key.c                               */
/*  NOTE      =                                                    */
/*  DATE      = 2015/02/02 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frsutl.h"
#include "frstat_topology.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

int __frhash_make_key(int i_l7_proto, u_int ui_ip, u_short us_port
                          , char *p_key, unsigned int ui_key_size);

static void case1(void)
{
    int i_ret = 0;
    int i_l7_proto = 1433;
    u_int ui_ip = iptools_parse_ipaddr("192.168.1.1");
    u_short us_port = 80;
    char *p_key = NULL;
    unsigned int ui_key_size = 0;

    i_ret = __frhash_make_key(i_l7_proto, ui_ip, us_port, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret,0);

    return;
}

static void case2(void)
{
    int i_ret = 0;
    int i_l7_proto = 1433;
    u_int ui_ip = iptools_parse_ipaddr("192.168.1.1");
    u_short us_port = 80;
    char *p_key = NULL;
    unsigned int ui_key_size = 10;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00,ui_key_size);

    i_ret = __frhash_make_key(i_l7_proto, ui_ip, us_port, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret,0);

    frfree(p_key);
    return;
}

static void case3(void)
{
    int i_ret = 0;
    int i_l7_proto = 1433;
    u_int ui_ip = iptools_parse_ipaddr("192.168.1.1");
    u_short us_port = 80;
    char *p_key = NULL;
    unsigned int ui_key_size = 11;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00,ui_key_size);

    i_ret = __frhash_make_key(i_l7_proto, ui_ip, us_port, p_key, ui_key_size);

    CU_ASSERT_NOT_EQUAL(i_ret,0);

    frfree(p_key);
    return;
}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__frhash_make_key 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);
   	CU_add_test(pSuite, "case3", case3);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}